package After826.Thread;

import java.util.Scanner;
import java.util.concurrent.Callable;

public class ThreadTest
{
    public static void main(String[] args) {
//        FutureTask< Integer>  futureTask = new FutureTask<Integer>((Callable<Integer>)()->{
//            System.out.println("Hello World");
//            return 1;
//        });
//        new Thread(futureTask).start();
//       Thread2 thread2 = new Thread2();
//       FutureTask futureTask = new FutureTask(thread2);
//       new Thread(futureTask).start();
//       Thread0 thread0 = new Thread0();
//       thread0.start();
//       new Thread( new Thread1()).start();
        Thread th3 = new CountThread();
        System.out.println("如果停止请按S");
        th3.start();
        Scanner input = new Scanner(System.in);
        while (true){
            String s = input.nextLine();
            if (s.equals("s")) {
                th3.interrupt();
                break;
            }
            System.out.println("计数结束");
        }

    }
}
class CountThread extends  Thread{
    private int count = 1;
    public CountThread(){
        super("计数线程");
    }
    @Override
    public void  run(){
        try {
            while(count<1000) {
                System.out.println(this.getName() + "计数:" + count + "次");
                count++;
                sleep(2000);
            }
            }catch (InterruptedException e) {
            System.out.println("线程结束");
            }catch (Exception e){
            e.printStackTrace();
        }
    }
}
class Thread2 implements Callable<Integer>{
    @Override
    public Integer call() throws Exception{
        System.out.println("Hello World");
        return 1;
    }
}
class  Thread0 extends  Thread{
    @Override
    public  void  run(){
        for (int i = 0; i < 10; i++) {
            System.out.println(i);
        }
    }
}
class Thread1 implements Runnable{
    @Override
    public  void  run(){
        for (int i = 0; i < 10; i++) {
            System.out.println(i);
        }
    }
}